{{- if .Values.flantIntegration.internal.madisonAuthKey }}
---
apiVersion: v1
kind: Service
metadata:
  name: madison-proxy
  namespace: d8-monitoring
  {{- include "helm_lib_module_labels" (list . (dict "app" "madison-proxy")) | nindent 2 }}
spec:
  type: ClusterIP
  clusterIP: None
  ports:
  - name: http
    port: 8080
    protocol: TCP
    targetPort: http
  selector:
    app: madison-proxy
  {{- if and (.Values.global.enabledModules | has "prometheus-crd") (.Values.global.enabledModules | has "prometheus") }}
---
apiVersion: deckhouse.io/v1alpha1
kind: CustomAlertmanager
metadata:
  name: madison-proxy
  {{- include "helm_lib_module_labels" (list . (dict "app" "madison-proxy")) | nindent 2 }}
spec:
  type: External
  external:
    service:
      namespace: d8-monitoring
      name: madison-proxy
    {{- if .Values.flantIntegration.grafanaAlertsToMadisonEnabled }}
---
apiVersion: deckhouse.io/v1alpha1
kind: GrafanaAlertsChannel
metadata:
  name: madison-proxy
  {{- include "helm_lib_module_labels" (list . (dict "app" "madison-proxy")) | nindent 2 }}
spec:
  description: "Channel to send alerts to Polk. Auto-created by flant-integration module."
  type: PrometheusAlertManager
  # TODO: think about disable default from config
  isDefault: true
  alertManager:
    address: {{ printf "http://madison-proxy.d8-monitoring.svc.%s:8080" .Values.global.discovery.clusterDomain | quote }}
    {{- end }}
  {{- end }}
{{- end }}
